Hi there, I have been writing some code to convert a number in base x to base y. During the operations, I would like to null the integer array so I can re-use it, so I don't have to create another integer array.
Do I have to create a pointer to this array and use that the whole way through until it is time to null the pointer? Or is there a way do this? Forgive my ignorance, it seems like there should be an easy answer but I cannot find it by googling.Code:int a[20]; /*give a some elements*/ a = NULL /*not allowed*/
Thanks
ps: if you need my code:
Code:#include <stdio.h> #include <stdlib.h> #include <math.h> #define SIZE 20 void toDecimal(int base, int num[], int len); int toBase(int base, int num, int a[]); void reverseit(int a[],int len); int arraytonum(int a[], int len); int main(int argc, char *argv[]) { if(argc > 5 || argc < 3) { printf("Usage: base 2210 4 5 \n(2210 in base 4 to base 5)\n"); exit(1); } char *num = argv[1]; int number[SIZE]; int anotherarray[SIZE]; /* i just want to null number[] and not use this */ int length=0; while(*num) { number[length] = *num - '0'; num++; length++; } int frombase = atoi(argv[2]); int tobase = atoi(argv[3]); toDecimal(frombase,number,length); int numero = arraytonum(number,length); /*number = NULL; (i wish to null it here) */ int newlen = toBase(tobase,numero,anotherarray); reverseit(anotherarray, newlen); int j; for(j=0;j<newlen;j++) { printf("anotherarray[%d]=%d\n", j, anotherarray[j]); } return 0; } void toDecimal(int base, int num[], int len) { int k; for(k=0;k<len;k++) { num[k] *= (int)pow(base,len-1-k); } } int toBase(int base, int num, int a[]) { int i=0; while( (num % base) != num ) { a[i] = num % base; num = (int)floor(num/base); i++; } a[i] = num; return i+1; } void reverseit(int a[], int len) { int i = 0; int temp; int loop = (int)floor(len/2); while(loop > 0) { temp = a[i]; a[i] = a[len-1-i]; a[len-1-i] = temp; loop--; i++; } } int arraytonum(int a[], int len) { int k; int num=0; for(k=0;k<len;k++) { num += a[k]; } return num; }


